/*
 * Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
 */
package src.com.bjsxt.height.design016_test;

import java.util.Random;
import java.util.concurrent.BlockingQueue;

/**
 * Description:消费者
 *
 * @author wzz
 * @since: 1.0
 * Create Date Time: 2018/11/1 16:08
 * Update Date Time:
 */
public class Consumer implements Runnable{

    private BlockingQueue<Data> queue;

    public Consumer(BlockingQueue<Data> queue){
        this.queue  = queue;
    }
    private Random r = new Random();
    @Override
    public void run() {

        while (true){
            try {
                Data data= queue.take();
                //模拟处理数据的时间
                Thread.sleep(r.nextInt(1000));
                System.out.println("当前消费线程:"+Thread.currentThread().getName()+"消费成功,id为:"+data.getId());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
